//
//  ChangePasswordViewController.m
//  TenThousand
//
//  Created by 我的 on 16/6/22.
//  Copyright © 2016年 baixue. All rights reserved.
//

#import "ChangePasswordViewController.h"
#import "ForgotPasswordViewController.h"

@interface ChangePasswordViewController ()<UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UITextField *verificationCode;
@property (weak, nonatomic) IBOutlet UIButton *mobleVerfication;//手机验证
@property (weak, nonatomic) IBOutlet UIButton *email;
@property (weak, nonatomic) IBOutlet UIButton *agreeBtn;
@property (weak, nonatomic) IBOutlet UIButton *nextBtn;

@end

@implementation ChangePasswordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"修改登录密码";
    [self createLeft:[UIImage imageNamed:@"ZHSZicon_03"] leftClick:^{
        [self.navigationController popViewControllerAnimated:YES];
    } right:nil rightClick:nil];
    self.agreeBtn.selected = YES;//默认为选中
    _oldPassword.secureTextEntry = YES;
    _password.secureTextEntry = YES;
    _configPassword.secureTextEntry = YES;
    
//    [self changePassword];
   
}

- (IBAction)agreeBtn:(UIButton *)sender {
    
    if (sender.selected) {
        sender.selected = NO;
        _nextBtn.enabled = NO;
    }else{
        sender.selected = YES;
        _nextBtn.enabled = YES;
    }
}

//忘记密码按钮
- (IBAction)forgotBtn:(id)sender {
    ForgotPasswordViewController *forgotView = [[ForgotPasswordViewController alloc] init];
    [self.navigationController pushViewController:forgotView animated:YES];
}

//发送验证码
- (IBAction)sendVerificationCode:(id)sender {
}

- (IBAction)sureChange:(id)sender {
    
    NSString *passWord = [[NSUserDefaults standardUserDefaults] objectForKey:@"Password"];
    if ([_oldPassword.text isEqualToString:@""]) {
        [ToastView showInfoWithStatus:@"请输入旧密码"];
    }else if (![_oldPassword.text isEqualToString:passWord]){
        [ToastView showInfoWithStatus:@"您输入的密码不符"];
    }else
        if([_password.text isEqualToString:@""]){
        [ToastView showInfoWithStatus:@"请输入新密码"];
    }else if([_configPassword.text isEqualToString:@""]){
        [ToastView showInfoWithStatus:@"请再次输入新密码"];
    }else if(![_password.text isEqualToString:_configPassword.text]){
        [ToastView showInfoWithStatus:@"两次密码不一致, 请重新输入"];
    }else{
    
        [self changePassword];
        [[NSUserDefaults standardUserDefaults] setObject:_configPassword.text forKey:@"Password"];
    }
    
//    [self changePassword];
    
}
//修改密码接口
- (void)changePassword{
    
//    http://test.open.wanyuanfu.net/api/user/openapi   User.GetUpdatePwd
    
    
    NSString *userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"LoginName"];
    NSDictionary *para = @{@"LoginName":userId,@"NewPassword":_password.text};
    
    [NetWorkManager requestWithType:HttpRequestTypePost withMethodName:@"User.GetUpdatePwd" withParaments:para withSuccessBlock:^(NSDictionary *object) {
        
        [ToastView showInfoWithStatus:object[@"Message"]];
        
        [self.navigationController popViewControllerAnimated:YES];
        
    } withFailureBlock:^(NSError *error) {
        NSLog(@"%@",error);
    } progress:nil];
    
}


//空白去键盘

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

{
    
    [self.view.window endEditing:YES];
    
}


@end
